<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <common-head></common-head>
  </div>
  <script src="./vue.js"></script>
  <script>
    const CommonHead = {
      template:`
        <div>
          <h1>这是一个组件</h1>
          <button @click="addLi">
            增加li
          </button>
          <ul ref="oul">
            <li v-for="item in arr" :key="item">
              {{item}}  
            </li>  
          </ul>
        </div>
      `,
      data(){
        return {
          arr:[1,2,3,4]
        }
      },
      methods: {
        addLi(){
          this.arr.push(this.arr.length+1);
          this.$nextTick(()=>{
            console.log(111);
            this.$refs.oul.lastElementChild.style.background="red"
          });

        }
      },
      beforeCreate() {
        console.log('实例创建之前')
      },
      created() {
        console.log('实例创建完成')
      },
      beforeMount(){
        console.log('dom渲染之前')
      },
      mounted(){
        console.log('dom渲染完成');
      },
      beforeUpdate() {
        console.log('数据改变dom更新之前')
      },
      updated() {
        console.log('dom更新完毕');
        // console.log(this.$refs.oul.children);
        // this.$refs.oul.lastElementChild.style.background="green";
      },
      beforeDestroy() {
        console.log('组件卸载之前')
      },
      destroyed() {
        console.log('组件已经卸载')
      },
    }
    Vue.component('CommonHead', CommonHead)
    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>
</html>